package org.example.bankMessage;

import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;
import java.util.Map;

public class MessageConsumer {

    public static void main(String[] args) {
        // 实例化消费者
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name");

        // 设置NameServer的地址
        consumer.setNamesrvAddr("192.168.14.129:9876");

        // 订阅一个或者多个Topic，以及Tag来过滤需要消费的消息
        try {
            consumer.subscribe("ee", "*");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

class BankAccountMessageListener implements MessageListenerOrderly {

    @Override
    public ConsumeOrderlyStatus consumeMessage(List<MessageExt> list, ConsumeOrderlyContext consumeOrderlyContext) {
        for (MessageExt msg : list) {
            Map<String,Object> map = JSON.parseObject(new String(msg.getBody()), Map.class);
            //获取发送消息时放入的键值
            String remark=(String)map.get("remark");
        }
        return null;
    }
}
